<?php session_start();
	include('../controller/functions.php');
	require_once '../controller/validation.php';
	User::connection();

$userArr	= array('admin','teacher','student');
	if(!in_array($_SESSION['user'],$userArr)) {
	User::validSession();

}
if ($_GET['q'] == 'logout') 
{
	User::user_logout();
	print '		
			<script type="text/javascript">		
			window.location = "../login_r.php";
			</script>
			';


}
if (isset ($_GET['userid'])) {
		$userid	= $_GET['userid'];
	
	}	
$queryForStudent = "SELECT u.fname, u.lname,u.mname, u.userid FROM tbluser u WHERE u.userid = '$_GET[userid]'";

$q = mysql_query($queryForStudent);

while($rowForStudent = mysql_fetch_assoc($q)):

$fullName = $rowForStudent['lname'].", ".$rowForStudent['fname'] ." ". $rowForStudent['mname'];

endwhile;

?>


<script type="text/javascript" src="../javascripts/jquery-1.5.js"></script>
	<script type="text/javascript" src="../javascripts/validation.js"></script>
    <script type="text/javascript" src="../javascripts/jquery-ui-1.7.2.custom.min.js"> </script>
    
  

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="shortcut icon" href="../images/fav.ico">
<link rel="icon" type="image/gif" href="../images/fav.ico">
<title>Registration of Student's Adviser</title>

	<link rel="stylesheet" href="../css/style2.css" type="text/css" charset="utf-8" />
 	<link rel="stylesheet" href="../css/general.css" type="text/css" charset="utf-8" />
    <link rel="stylesheet" href="../css/jquery-ui-1.7.2.custom.css" type="text/css" charset="utf-8" />
</head>

<body>

 <div id="page">
<div id="wrapper">
        	
        		   <div class="header_top" id="header_top"> </div>
  </div>
  <div class="header2"></div> 
	<div class="header"><!--open logo -->
		  </div><!--end header -->
	<!-- close logo-->
<!-- nav-->    <?php
    echo '<div id="nav">';
    echo '<div class="underlinemenu">';
	include('menu_view.php');
	echo '</div>';
    echo '</div>';
	?>
    <div id="header_in"> <!--open header -->
         <p> </p>
    <table width="100%" height="56">
     <tr>
       <td width="317" align="left" class="date"> 
        <? User::oras(); ?>
        </td>
            
       <td width="388" align="right"><? User::showPic(); ?></td>
       <td width="279">&nbsp;&nbsp;<? User::showUser(); ?>        </td>
       </tr>
   </table>
    </div>
    <div id="ex">
    </div>
      <p> </p>
       <div id="body"> <!--open body -->
    
	 <div id="sidebar"> 
        <div id="chef_ind"> <!--open chef --><!--close welcome-->

<? echo '<p class="more">';
echo '';
 
   require('sideBar.php');
    
echo'</p>';
?>

        </div>
        
      </div><!--close left -->
      
       
      <div id="content"> 
 	<div id="container">
		<h1>Add Adviser [<? print($fullName); ?>]</h1>
		
		
					</ul>
		</div>
		<!--Registration for students -->
				
				<? if(isset($_POST['send'])):
				
				$password = mt_rand() . mt_rand() . mt_rand();
				$qqqq = "SELECT u.userid,s.sectionName,s.sectionid, u.fname,u.lname,u.mname
	    FROM tbluser u INNER JOIN tblsection s ON s.sectionAdviser = u.userid
	    WHERE s.sectionAdviser = '$_POST[secAd]' ";
		
		$queryAd = mysql_query($qqqq);
		while($r = mysql_fetch_assoc($queryAd)){
			$adviserName = $r['lname'].", ".$r['mname'] ." ". $r['fname'] ;
			$neWsectionName = $r['sectionName'];
			
		}
    $query = sprintf("INSERT INTO `tblsection`(`sectionName`,`roomName`,`sectionAdviser`,`date`,`adviserName`,`studentName`,`studentNumber`,`yearLevel`) VALUES('$neWsectionName','$_POST[roomName]','$_POST[secAd]',NOW(),'$adviserName','$fullName','$_GET[userid]',0)");
	$res = @mysql_query($query);
		
	
	$query1 = sprintf("UPDATE `tbluser` SET `forumaccess` = 1, `status` = 'yes' WHERE userid = '$_GET[userid]' ");
	$res1 = @mysql_query($query1);
	
	if($res && $res1){
		
				
		echo '
		<script type="text/javascript">
		alert("Successfully Updated!");
		window.location = "viewStudents.php";
		</script>
		 ';
		 
		 echo ' <a href="viewStudents.php">View&nbsp;Students </a>';
	}
	else{
		echo '<div id="error">Error occured while saving!</div>';
	}  
	
	if(!$res && !$res1)
		die("Error: ".mysql_error());
	else
		$r = $res . " ". $res1;
		return $r;
			
            ?>
            
            <div id="error" class="valid">
					<ul>
						<li><strong>Congratulations!</strong> All fields are OK ;)</li>
					</ul>
		</div>	
		<?endif?>

		<form method="post" id="regStudentadviser" action="">
        <label for="secNamediv">Section Name</label>
        <div>
        
        
<?

				$q	= 				"SELECT  s.sectionid, s.sectionName
												 FROM tblsection s WHERE s.studentName = 'none'
												  ;		
									";
									$select		= 	"<select id='secName' name='secName' onChange='getRoomName(this.value)'>";	
									$select .= "<option value = 0 selected='selected' >Select Section</option>";		
									$temp 	= mysql_query($q);	
									while ($selName	= mysql_fetch_assoc($temp)) {		
										$secIDd = $selName['sectionid'];
										$n = $selName['sectionName'];
										$select .= "<option value = '".$secIDd."'>	".$n."</option>";
										
									}
									$select	   .= 	"</select>";
									
									$secAdvName	= $select;
									
									print($secAdvName);
?>
        </div>
          <label for="roomNamediv">Room Name</label>
			<div id="roomNamediv"><select name="roomName" >
	<option>Select Room Name</option>
        </select></div>
        
          <label for="secAdiv">Section Adviser</label>
        <div id="secAdiv">
       
        <select name="secAd">
        
	<option>Select Adviser</option>
        </select></div>
      
        
  
			<div>
				<input id="send" name="send" type="submit" value="Send" />
			</div>
		</form>
        
		<? 
		//query for section
		
		$classQ		= "SELECT * FROM tblsection s INNER JOIN tblclass c ";
 		$classQ	   .= "ON s.sectionName = c.sectionName WHERE s.adviserName != 'none' AND s.studentName = 'none' ";
		$classQ    .= "AND s.sectionName = c.sectionName GROUP BY  s.sectionid ORDER BY c.subjectID";
		
		$classQuery = mysql_query($classQ);
		$noOfclass = mysql_num_rows($classQuery);
		$ctr = 1;
		$loop = 1;
		while($ctr <= $noOfclass){
		while($rowClass = mysql_fetch_assoc($classQuery)) {
			$adviserName	= $rowClass['adviserName'];
		$sectionN	= "$loop. ".$rowClass['sectionName'];
		$sectionNn	= "<strong>".$rowClass['sectionName']."</strong>";
		$mak		= $rowClass['makabayan'];
		$mak1		= $rowClass['makabayan1'];
		$mak2		= $rowClass['makabayan2'];
		$mak3		= $rowClass['makabayan3'];
		$mak4		= $rowClass['makabayan4'];
		$fil		= $rowClass['filipino'];
		$eng		= $rowClass['english'];
		$mat		= $rowClass['math'];
		$sci		= $rowClass['science'];
		
		$oras1		= $rowClass['makaOras'];
		$oras2		= $rowClass['makaOras1'];
		$oras3		= $rowClass['maka1Oras'];
		$oras4		= $rowClass['maka1Oras1'];
		$oras5		= $rowClass['maka2Oras'];
		$oras6		= $rowClass['maka2Oras1'];
		$oras7		= $rowClass['maka3Oras'];
		$oras8		= $rowClass['maka3Oras1'];
		$oras9		= $rowClass['maka4Oras'];
		
		$oras10		= $rowClass['maka4Oras1'];
		$oras11 	= $rowClass['filiOras'];
		$oras12		= $rowClass['filiOras1'];
		$oras13		= $rowClass['englOras'];
		$oras14		= $rowClass['englOras1'];
		$oras15		= $rowClass['mathOras'];
		$oras16		= $rowClass['mathOras1'];
		$oras17		= $rowClass['scieOras'];
		$oras18		= $rowClass['scieOras1'];
		
		$loop++;
		}
		$ctr++;
	}

		
		?>
        
        <div id='basic-modal'>
    <span class="bold_">Available Section </span>
    <br />
      <br />
    <a href = "#" title = "Click to view" class="bas"><? print($sectionN); ?></a>	
  </div>
        
      </div>
      <!--close desc -->
    	</div> <!--close right-->
        <div id="basic-modal-content">
        <h3><? print($sectionNn); ?></h3>
        <p><? print($adviserName); ?> </p>
      <table width="100%"style="font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif; font-size:9pt;">
             <tr bgcolor="#FFFFFF" style = "font-color:#444444;">
               <td align="center" width="15%"><b>Makabayan</b></td>
               <td align="center" width="15%"><b>Makabayan 1</b></td>
               <td align="center" width="15%"><b>Makabayan 2</b></td>
               <td align="center" width="15%"><b>Makabayan 3</b></td>
               <td align="center" width="15%"><b>Makabayan  4</b></td>
               <td align="center" width="15%"><b>Filipino</b></td>
               <td align="center" width="15%"><b>English</b></td>
               <td align="center" width="15%"><b>Math</b></td>
               <td align="center" width="15%"><b>Science</b></td>
             </tr>
             <? 
			 print '<tr bgcolor="#EEEEEE" style="font-color:#666666;">
			   <td align="center" width="15%">'.$mak.'</td>
               <td align="center" width="15%">'.$mak1.'</td>
               <td align="center" width="15%">'.$mak2.'</td>
               <td align="center" width="15%">'.$mak3.'</td>
               <td align="center" width="15%">'.$mak4.'</td>
               <td align="center" width="15%">'.$fil.'</td>
               <td align="center" width="15%">'.$eng.'</td>
               <td align="center" width="15%">'.$mat.'</td>
               <td align="center" width="15%">'.$sci.'</td>
			 </tr>';
			 
			 
			 print '<tr bgcolor="#EEEEEE" style="font-color:#666666;">
			   <td align="center" width="15%">'.$oras1.'</td>
               <td align="center" width="15%">'.$oras3.'</td>
               <td align="center" width="15%">'.$oras5.'</td>
               <td align="center" width="15%">'.$oras7.'</td>
               <td align="center" width="15%">'.$oras9.'</td>
               <td align="center" width="15%">'.$oras11.'</td>
               <td align="center" width="15%">'.$oras13.'</td>
               <td align="center" width="15%">'.$oras15.'</td>
               <td align="center" width="15%">'.$oras17.'</td>
			 </tr>';
			 
			  print '<tr bgcolor="#EEEEEE" style="font-color:#666666;">
			   <td align="center" width="15%">'.$oras2.'</td>
               <td align="center" width="15%">'.$oras4.'</td>
               <td align="center" width="15%">'.$oras6.'</td>
               <td align="center" width="15%">'.$oras8.'</td>
               <td align="center" width="15%">'.$oras10.'</td>
               <td align="center" width="15%">'.$oras12.'</td>
               <td align="center" width="15%">'.$oras14.'</td>
               <td align="center" width="15%">'.$oras16.'</td>
               <td align="center" width="15%">'.$oras18.'</td>
			 </tr>';
			 ?>
             
             
           </table>
           
    </div>
      <div class="clear">&nbsp;</div>
 <!-- footer-->
<?php 
	  echo '<div id="footer">';
     include('footer_view.php');
      echo '</div>';	
	  ?>

    </div><!-- close body-->
</div><!-- close page-->

<script language="javascript" type="text/javascript">
// Roshan's Ajax dropdown code with php
// This notice must stay intact for legal use
// Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com
// If you have any problem contact me at http://roshanbh.com.np
function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
    }
	
	function getRoomName(secName) {		
		
		var strURL="findRoom.php?secName="+secName;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('roomNamediv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
	function getSecAd(secName) {		
		var strURL="findSec.php?secName="+secName;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('secAdiv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
				
	}
</script>
</body>
</html>



